
// 不同请求的处理
const reducer = (state, action) => {
    switch (action.type) {
        case 'line':{
            return {
                ...state,
                compare:0,
                line:1,
                is_pie:1
            }
        }
        case 'compare':{
            return {
                ...state,
                compare:1,
                line:0,
                is_pie:0,
                is_bar:0
            }
        }
        case 'pie':{
            return{
                ...state,
                is_pie:1,
                is_bar:0,
                compare:0
            }
        }
        case 'changeyear':{
            return {
                ...state,
                year:document.getElementById('year').value,
                compare:0,
                line:0
            };
        }
        case 'increment':
            return {
                ...state,
                count: state.count + 1,
                is_pie:0,
                is_bar:1,
                compare:0
            };
        case 'init': {
            let newData = [];
            // TODO: use action.payload to update newData
            newData = action.payload;
            // console.log(newData[0]);
            return {
                ...state,
                data: newData
            };
        }
        default:{
            throw new Error();
        }
    }
}

export default reducer;